package com.daveclay.boilermaker

import javax.ws.rs._
import com.google.inject.{Singleton, Inject}
import web.InitParamLookup
import java.util

@Singleton
@Path("/services")
class BoilermakerService @Inject()(initParamLookup:InitParamLookup) {

    def thingWithId(id: String) = {
        new Thing(id, 9, new util.Date())
    }

    var things = Array(thingWithId("A1"), thingWithId("2B"))

    @GET
	@Path("/all")
	@Produces(Array("application/json"))
	def getThings = {
        things
	}

	@GET
	@Path("/{id}")
	@Produces(Array("application/json"))
	def getThing(@PathParam("id") id: String) = {
        things.find({ thing => {
            thing.name == id
        }})
	}

	@POST
	@Path("/{id}")
    @Consumes(Array("text/json", "application/json"))
    @Produces(Array("application/json"))
	def createThing(thing: Thing) = {
        things = things ++ Array(thing)
        Response(success = true)
	}

    case class Response(success:Boolean)
}
